<template>

  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <span>派工列表</span>
      <el-button style="float: right; padding: 3px 0" type="text" ></el-button>
    </div>

  <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="80px">

     <el-form-item label="派工类别 " prop="sendtype" style="margin-bottom: 2px;">
        <el-select v-model="queryParams.sendtype" placeholder="请选择派工类别 " clearable size="small">
          <el-option
            v-for="dict in sendtypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="科室/部门" prop="useoffice" style="margin-bottom: 2px;">
        <el-select v-model="queryParams.useoffice" placeholder="请选择使用科室" clearable size="small">
          <el-option
            v-for="dict in useofficeOptions"
            :key="dict.deptId"
            :label="dict.deptName"
            :value="dict.deptId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="设备型号" prop="devicemodel" style="margin-bottom: 2px;">
        <el-input
          v-model="queryParams.devicemodel"
          placeholder="请输入设备型号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
        </el-form-item>
        <el-form-item label="责任人" prop="membername" style="margin-bottom: 2px;">
          <el-input
            v-model="queryParams.membername"
            placeholder="请输入责任人"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
          </el-form-item>

      <el-form-item label="服务状态" prop="servicestatus" style="margin-bottom: 2px;">
        <el-select v-model="queryParams.servicestatus" placeholder="请选择服务状态" clearable size="small">
          <el-option
            v-for="dict in servicestatusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="sendorderList" :row-style="getClass">
      <el-table-column label="单位名称 " align="center" prop="zyxDevice.unitname" />
      <el-table-column label="科室/部门 " align="center" prop="useoffice" :formatter="useofficeFormat"/>
      <el-table-column label="设备类别 " align="center" prop="devicetype" />
      <el-table-column label="设备型号" align="center" prop="zyxDevice.devicemodel" />
      <el-table-column label="派工类别 " align="center" prop="sendtype" :formatter="sendtypeFormat" />
      <el-table-column label="服务状态" align="center" prop="servicestatus" :formatter="servicestatusFormat" />
      <el-table-column label="派工时间" align="center" prop="senddate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.senddate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="进行时间" align="center" prop="processdate" />
      <el-table-column label="责任人 " align="center" prop="membername" />
      <el-table-column label="备注信息" align="center" prop="remark" />

    </el-table>
    <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
    </el-card>
</template>
<script>
import { listHomeSendorder} from "@/api/zyx/sendorder";
import { listMyDept,  } from "@/api/system/dept";

export default {
  components: {

  },
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 派工表格数据
      sendorderList: [],
      // 派工类别 字典
      sendtypeOptions: [],
      // 服务状态字典
      servicestatusOptions: [],
      devicetypeOptions:[],
      useofficeOptions:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 6,
        devicemodel:null,
        departid: null,
        useoffice:null,
        deviceid: null,
        sendtype: null,
        servicestatus: null,
        processdate: null,
        memberid: null,
        overdate: null,
        membername:null,
        orderByColumn:'senddate',
        isAsc:'desc',
      },
        oneclass:{
          "color":"red"
        },
        twoclass:{
          "color":"blue"
        },
        threeclass:{
          "color":"orange"
        },
        fourclass:{
          "color":"green"
        }
    }
  },
  created() {
    this.getList();
    this.getDicts("zyx_sendtype").then(response => {
      this.sendtypeOptions = response.data;
    });
    this.getDicts("zyx_servicestatus").then(response => {
      this.servicestatusOptions = response.data;
    });
    this.getDicts("zyx_devicetype").then(response => {
         this.devicetypeOptions = response.data;
       });
     listMyDept({deptType:'2'}).then(response => {
       // console.log(response)
       this.useofficeOptions = response.data;
     });
  },
  methods: {
    getClass(row){
      if(row.row.servicestatus==='1'){
        return this.oneclass;
      }else if(row.row.servicestatus==='2'){
          return this.twoclass;
      }else if(row.row.servicestatus==='3'){
          return this.threeclass;
      }else if(row.row.servicestatus==='4'){
          return this.fourclass;
      }

    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        departid: null,
        deviceid: null,
        sendtype: null,
        devicestatus: null,
        servicestatus: null,
        senddate: null,
        processdate: null,
        memberid: null,
        overdate: null,
        useoffice:null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        delFlag: null
      };
      this.resetForm("form");
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
   /** 查询派工列表 */
      getList() {
        this.loading = true;
        listHomeSendorder(this.queryParams).then(response => {
          this.sendorderList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 派工类别 字典翻译
      sendtypeFormat(row, column) {
        return this.selectDictLabel(this.sendtypeOptions, row.sendtype);
      },
      // 服务状态字典翻译
      servicestatusFormat(row, column) {
        return this.selectDictLabel(this.servicestatusOptions, row.servicestatus);
      },
      // 设备类别字典字典翻译
      devicetypeFormat(row, column) {
        return this.selectDictLabel(this.devicetypeOptions, row.devicetype);
      },
      // 使用科室字典字典翻译
      useofficeFormat(row, column) {
        // console.log(this.selectDeptLabel(this.useofficeOptions, row.useoffice))
        return this.selectDeptLabel(this.useofficeOptions, row.useoffice);
      },

  }
}
</script>

<style lang="scss" scoped>

</style>
